import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
import createLogger from 'vuex/dist/logger'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    list: []
  },
  mutations: {
    // 修改 list的 唯一方法
    SET_LIST(state, payload) {
      state.list = payload
    }
  },
  actions: {
    // 请求数据 允许异步
    async fetchList(context) {
      let resp = await axios.get('/api/home/list');
      context.commit('SET_LIST', resp.data.data)
    }
  },
  modules: {
  },
  plugins: [
    createLogger()
  ]
})
